package xyz.gzdxc.common.util;

import xyz.gzdxc.common.constant.ResultCode;
import xyz.gzdxc.common.vo.response.ResultVo;

public class ResultBuilder {

    /**
     * success
     */
    public static ResultVo success(){
        return build(ResultCode.SUCCESS);
    }

    /**
     * construct the result when process success
     *
     * @param data the response business data
     * @return
     */
    public static ResultVo build(Object data){
        return build(ResultCode.SUCCESS, data);
    }

    /**
     * specify status code and description
     */
    public static ResultVo build(ResultCode resultCode){
        return build(resultCode, null);
    }

    /**
     * specify the status code and description, and the response business data
     *
     * @param data the response business data
     * @return
     */
    public static ResultVo build(ResultCode resultCode, Object data){
        ResultVo result = new ResultVo();
        result.setRetcode(resultCode.getRetcode());
        result.setMsg(resultCode.getMsg());
        result.setData(data);
        return result;
    }
}
